package hotel.modal;

import hotel.dao.CustomerTypeDao;
import javafx.beans.property.*;

public class CustomerType {
	private SimpleIntegerProperty customerTypeId;	// 会员类型编号
	private SimpleStringProperty typeName;			// 会员类型名称
	private SimpleDoubleProperty discountRate;		// 折扣率
	protected SimpleBooleanProperty modified;
	
	private void init(CustomerTypeDao ctd) {
		if(ctd != null) {
			this.customerTypeId = new SimpleIntegerProperty(ctd.getCustomerTypeId());
			this.typeName = new SimpleStringProperty(ctd.getTypeName());
			this.discountRate = new SimpleDoubleProperty(ctd.getDiscountRate());
		}else {
			this.customerTypeId = new SimpleIntegerProperty(0);
			this.typeName = new SimpleStringProperty("非会员");
			this.discountRate = new SimpleDoubleProperty(1.0);
		}
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public CustomerType(CustomerTypeDao ctd) {
		init(ctd);
	}
	
	public CustomerType() {
		init(null);
	}
	
	public Object getDao() {
		CustomerTypeDao ctd = new CustomerTypeDao();
		ctd.setCustomerTypeId(customerTypeId.get());
		ctd.setTypeName(typeName.get());
		ctd.setDiscountRate(discountRate.get());
		return ctd;
	}
	
	public CustomerType(CustomerType customType) {
		this.customerTypeId = new SimpleIntegerProperty(customType.getCustomerTypeId());
		this.typeName = new SimpleStringProperty(customType.getTypeName());
		this.discountRate = new SimpleDoubleProperty(customType.getDiscountRate());
		this.modified = new SimpleBooleanProperty(customType.isModified());
	}
	
	public CustomerType(int customerTypeId, String typeName, double discountRate) {
		this.customerTypeId = new SimpleIntegerProperty(customerTypeId);
		this.typeName = new SimpleStringProperty(typeName);
		this.discountRate = new SimpleDoubleProperty(discountRate);
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public final SimpleIntegerProperty customerTypeIdProperty() {
		return this.customerTypeId;
	}
	
	public final int getCustomerTypeId() {
		return this.customerTypeIdProperty().get();
	}
	
	public final void setCustomerTypeId(final int customerTypeId) {
		this.customerTypeIdProperty().set(customerTypeId);
	}
	
	public final SimpleStringProperty typeNameProperty() {
		return this.typeName;
	}
	
	public final String getTypeName() {
		return this.typeNameProperty().get();
	}
	
	public final void setTypeName(final String typeName) {
		this.typeNameProperty().set(typeName);
	}
	
	public final SimpleDoubleProperty discountRateProperty() {
		return this.discountRate;
	}
	
	public final double getDiscountRate() {
		return this.discountRateProperty().get();
	}
	
	public final void setDiscountRate(final double discountRate) {
		this.discountRateProperty().set(discountRate);
	}

	public final SimpleBooleanProperty modifiedProperty() {
		return this.modified;
	}
	

	public final boolean isModified() {
		return this.modifiedProperty().get();
	}
	

	public final void setModified(final boolean modified) {
		this.modifiedProperty().set(modified);
	}
	
	public String toString() {
		String str = String.format("CustomerTypeID:%d TypeName:%s DiscountRate:%.2f", 
				customerTypeId.get(), typeName.get(), discountRate.get());
		return str;
	}
	
}
